home *** CD-ROM | disk | FTP | other *** search
- Imports System.Drawing.Drawing2D
-
- Public Class Transformations
- Inherits System.Windows.Forms.Form
-
- #Region " Windows Form Designer generated code "
-
- Public Sub New()
- MyBase.New()
-
- 'This call is required by the Windows Form Designer.
- InitializeComponent()
-
- 'Add any initialization after the InitializeComponent() call
-
- End Sub
-
- 'Form overrides dispose to clean up the component list.
- Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
- If disposing Then
- If Not (components Is Nothing) Then
- components.Dispose()
- End If
- End If
- MyBase.Dispose(disposing)
- End Sub
- Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
- Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
- Friend WithEvents mnuTranslateRotate As System.Windows.Forms.MenuItem
-
- 'Required by the Windows Form Designer
- Private components As System.ComponentModel.Container
-
- 'NOTE: The following procedure is required by the Windows Form Designer
- 'It can be modified using the Windows Form Designer.
- 'Do not modify it using the code editor.
- <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
- Me.MainMenu1 = New System.Windows.Forms.MainMenu()
- Me.MenuItem1 = New System.Windows.Forms.MenuItem()
- Me.mnuTranslateRotate = New System.Windows.Forms.MenuItem()
- '
- 'MainMenu1
- '
- Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1})
- '
- 'MenuItem1
- '
- Me.MenuItem1.Index = 0
- Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuTranslateRotate})
- Me.MenuItem1.Text = "Examples"
- '
- 'mnuTranslateRotate
- '
- Me.mnuTranslateRotate.Index = 0
- Me.mnuTranslateRotate.Text = "Translate and Rotate"
- '
- 'Transformations
- '
- Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
- Me.ClientSize = New System.Drawing.Size(528, 269)
- Me.Menu = Me.MainMenu1
- Me.Name = "Transformations"
- Me.Text = "Transformations"
-
- End Sub
-
- #End Region
-
- Private Sub mnuTranslateRotate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuTranslateRotate.Click
- ' Wait until the menu closes.
- Threading.Thread.Sleep(400)
-
- Dim gr As Graphics = Me.CreateGraphics
- gr.Clear(Color.White)
-
- gr.PageUnit = GraphicsUnit.Millimeter
- gr.PageScale = 0.1
-
- ' Create a Path that we can draw multiple times.
- Dim pa As New GraphicsPath()
- pa.AddRectangle(New Rectangle(20, 20, 200, 100))
- pa.AddEllipse(New Rectangle(30, 30, 180, 80))
- ' Draw the path without any transformation.
- gr.DrawPath(Pens.Black, pa)
-
- ' Apply a translation and redraw the path.
- gr.TranslateTransform(30, 200)
- gr.DrawPath(Pens.Red, pa)
-
- ' Apply both a translation and a rotation, and redraw the Path.
- gr.ResetTransform()
- gr.TranslateTransform(400, 0)
- gr.RotateTransform(30)
- gr.DrawPath(Pens.Green, pa)
-
- ' translate again, change the scale and redraw.
- gr.ResetTransform()
- gr.TranslateTransform(300, 200)
- ' create multiple shapes that vary in angle and scale.
- Dim i As Integer
- Dim scaleX As Single = 1
- Dim scaleY As Single = 1
- For i = 1 To 6
- gr.ScaleTransform(scaleX, scaleY)
- gr.DrawPath(Pens.Blue, pa)
- scaleX += 0.05
- scaleY += 0.1
- Next
-
- ' Destroy the Path object.
- pa.Dispose()
- ' Destroy the Graphics object.
- gr.Dispose()
- End Sub
- End Class
-